package cn.source.system.service.impl;

import java.util.ArrayList;
import java.util.List;
import cn.source.common.utils.DateUtils;
import cn.source.system.domain.dto.RoomDto;
import cn.source.system.utils.SnowflakeIdWorker;
import org.springframework.stereotype.Service;
import cn.source.system.mapper.RoomMapper;
import cn.source.system.domain.Room;
import cn.source.system.service.IRoomService;

import javax.annotation.Resource;

/**
 * 房间管理Service业务层处理
 *
 * @author gygl
 * @date 2023-08-01
 */
@Service
public class RoomServiceImpl implements IRoomService
{
    @Resource
    private RoomMapper roomMapper;

    /**
     * 查询房间管理
     *
     * @param roomId 房间管理主键
     * @return 房间管理
     */
    @Override
    public Room selectRoomByRoomId(Long roomId)
    {
        return roomMapper.selectRoomByRoomId(roomId);
    }

    /**
     * 查询房间管理列表
     *
     * @param room 房间管理
     * @return 房间管理
     */
    @Override
    public List<Room> selectRoomList(Room room)
    {
        return roomMapper.selectRoomList(room);
    }

    /**
     * 新增房间管理
     *
     * @param room 房间管理
     * @return 结果
     */
    @Override
    public int insertRoom(Room room)
    {
        SnowflakeIdWorker snowflakeIdWorker = new SnowflakeIdWorker();
        room.setCreateTime(DateUtils.getNowDate());
        room.setRoomId(String.valueOf(snowflakeIdWorker.nextId()));
        return roomMapper.insertRoom(room);
    }

    /**
     * 修改房间管理
     *
     * @param room 房间管理
     * @return 结果
     */
    @Override
    public int updateRoom(Room room)
    {
        room.setUpdateTime(DateUtils.getNowDate());
        return roomMapper.updateRoom(room);
    }

    /**
     * 批量删除房间管理
     *
     * @param roomIds 需要删除的房间管理主键
     * @return 结果
     */
    @Override
    public int deleteRoomByRoomIds(Long[] roomIds)
    {
        return roomMapper.deleteRoomByRoomIds(roomIds);
    }

    /**
     * 删除房间管理信息
     *
     * @param roomId 房间管理主键
     * @return 结果
     */
    @Override
    public int deleteRoomByRoomId(Long roomId)
    {
        return roomMapper.deleteRoomByRoomId(roomId);
    }

    /**
     * 查询所有房间可用床位数量
     * @return
     */
    @Override
    public Object selectAvailableRoomCount(Room room) {
        List<Room> roomList = roomMapper.selectRoomList(room);
        for (Room item: roomList
             ) {
        }
        return null;
    }

    /**
     * 查询床位总数
     * @param room
     * @return
     */
    @Override
    public Object selectRoomAllList(Room room) {
        int count=0;
        List<Room> roomList = roomMapper.selectRoomList(room);
        for (Room item:roomList
             ) {
            int roomCapacity = item.getRoomCapacity();
            count += roomCapacity;
        }
        if (count != 0){
        return count;
        }
        else {
           return "未知错误";
        }
    }

    @Override
    public Room selectGetRoomByRoomNo(Long roomNo) {
        return roomMapper.selectGetRoomByRoomNo(roomNo);
    }

    @Override
    public List<Room> getRoomFloor(String roomFloor){
        return roomMapper.getRoomFloor(roomFloor);
    }


    @Override
    public List<RoomDto>  getRoomInfo(String roomNo){
        return roomMapper.getRoomInfo(roomNo);
    }


    @Override
    public List<String> getAllRoomNo(Room room) {
        List<Room> roomList = roomMapper.selectRoomList(room);
        List<String> roomNoList = new ArrayList<>();
        for (Room item: roomList) {
            String roomNo = item.getRoomNo();
            roomNoList.add(roomNo);
        }
        return roomNoList;
    }

}
